package com.conytech.conydishm;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;


public class MainActivity extends ActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if (savedInstanceState == null) {
		}

		isConnectOK();

		//첫번째 메뉴 자동 선택
		//View first_view = findViewById(R.id.menu1_btn);
		//mOnClick(first_view);

	}

	//네트워크 커넥션 없으면 종료
	public void isConnectOK() {
		ConnectivityManager mgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
		NetworkInfo ani = mgr.getActiveNetworkInfo();
		boolean isConnected = ani != null && ani.isConnectedOrConnecting();

		if(isConnected == false) {
			AlertDialog.Builder adialog = new AlertDialog.Builder(this);
			adialog
				.setTitle(R.string.error_app_title)
				.setMessage(R.string.error_message1)
				.setCancelable(false)
				.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int which) {
						System.exit(0);
					}
				})
				.show();
		}

	}

	//백 버튼 클릭시 종료
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		//백버튼
		if(keyCode == KeyEvent.KEYCODE_BACK) {
			confirmAppExit();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	//종료 확인 테스트
	private void confirmAppExit() {

		AlertDialog.Builder adialog = new AlertDialog.Builder(this);
		adialog
			.setTitle(R.string.exit_app_title)
			.setMessage(R.string.exit_app_message)
			.setCancelable(true)
			.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
				@Override
				public void onClick(DialogInterface dialog, int which) {
					System.exit(0);
				}
			})
			.setNegativeButton(android.R.string.cancel, null)
			.show();
	}





/*	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}*/

}
